import base64
import hmac
import urllib

from django.shortcuts import render,redirect
#导包
from django.http import HttpResponse,HttpResponseRedirect,JsonResponse
#导入类视图
from django.views import View


import json

from rest_framework.response import Response
from rest_framework.views import APIView
#导入加密库
import hashlib
#导入图片库
#绘画库
from PIL import ImageDraw
#字体库
from PIL import ImageFont
#图片库
from PIL import Image
#随机库
import random
#文件流
import io

import requests

#导入上传文件夹配置
from mydjango.settings import UPLOAD_ROOT
import os

#导入原生sql模块
from django.db import connection

import jwt

#导入redis数据库
import redis

#导入时间模块
import time

#导入公共目录变量,密钥
from mydjango.settings import BASE_DIR,SECRET_TOKEN


#导包
from django.db.models import Q,F

#导入dwebsocket的库
from dwebsocket.decorators import accept_websocket
import uuid

#导入序列化对象
from myapp.myser import UserSer

import redis

#   七牛云上传模块
from qiniu import Auth
# token模块
import jwt

from django.utils.decorators import method_decorator
from myapp.models import User,Pics
from myapp.myser import UserSer,PicsSer

# 展示所有幻灯片和插入幻灯片
class InsertPics(APIView):

    def delete(self,request):
        id = request.GET.get('id')

        Pics.objects.filter(id=id).first().delete()
        return Response({'message':"删除成功"})

    def get(self,request):

        pics = Pics.objects.all()
        ser = PicsSer(pics,many=True)
        return Response(ser.data)


    def post(self,request):
        title = request.data.get('title')
        link = request.data.get('link')
        image = request.data.get('image')

        user = Pics.objects.filter(title=title).first()

        if user:
            res = {}
            res['code'] = 405
            res['message'] = '活动存在'
            return Response(res)

        pics = Pics(title=title,link=link,image=image)
        pics.save()
        res = {}
        res['code'] = 200
        res['message'] = '保存成功'
        return Response(res)

